/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain.ai;

import Server.domain.MathHelper;
import Server.domain.Mob;
import Server.domain.Player;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Ripper
 */
public abstract class MobAI 
{
    private Mob controlledCreature;
    
    private List<Player> playersAwareOf;
    private List<Integer> aggroTowardsPlayers;
    
    public MobAI(Mob parent)
    {
        controlledCreature = parent;
        playersAwareOf = new ArrayList<Player>();
        aggroTowardsPlayers = new ArrayList<Integer>();
    }
    
    public void checkToSpotNewPlayers()
    {
        for(Player p: controlledCreature.getGamelevel().getPlayers())
        {
            if(!playersAwareOf.contains(p))
            {
                double distanceToPlayer = MathHelper.getDistanceBetween(p, controlledCreature);
                
                if(distanceToPlayer < 500)
                {
                    playersAwareOf.add(p);
                    aggroTowardsPlayers.add(0);
                }
            }
        }
    }
    public abstract void decideWhatToDo();
    public void think()
    {
        checkToSpotNewPlayers();
        decideWhatToDo();
    }
    
    public void damageTaken(Player damageSource, int damage, double aggroMpr)
    {
        //build aggro towards that player
        int index = -1;
        for(int a = 0; a < playersAwareOf.size();a++)
        {
            if(playersAwareOf.get(a) == damageSource)
            {
                index = a;
            }
        }
        
        if(index != -1)
        {
            int aggro = aggroTowardsPlayers.get(index);
            aggro += damage * aggroMpr;
            aggroTowardsPlayers.set(index, aggro);
        }
    }

    
    
    
    public List<Integer> getAggroTowardsPlayers() {
        return aggroTowardsPlayers;
    }

    public void setAggroTowardsPlayers(List<Integer> aggroTowardsPlayers) {
        this.aggroTowardsPlayers = aggroTowardsPlayers;
    }

    public Mob getControlledCreature() {
        return controlledCreature;
    }

    public void setControlledCreature(Mob controlledCreature) {
        this.controlledCreature = controlledCreature;
    }

    public List<Player> getPlayersAwareOf() {
        return playersAwareOf;
    }

    public void setPlayersAwareOf(List<Player> playersAwareOf) {
        this.playersAwareOf = playersAwareOf;
    }
    
    
}
